package cse.om.vswn;

public class Sensitivity implements Comparable<Sensitivity>{

	private static final Object[] STRONG_POSITIVE = {3, "strong_positive", "strong positive"};
	private static final Object[] POSITIVE = {2, "positive", "positive"};
	private static final Object[] WEAK_POSITIVE = {1, "weak_positive", "weak positive"};
	private static final Object[] NORMAL = {0, "normal", "normal"};
	private static final Object[] WEAK_NEGATIVE = {-1, "weak_negative", "weak negative"};
	private static final Object[] NEGATIVE = {-2, "negative", "negative"};
	private static final Object[] STRONG_NEGATIVE = {-3, "strong_negative", "strong negative"};
	private static final Object[] NOT_DETERMINED = {Integer.MIN_VALUE, "not_determined", "not determined"};

	private final Double score;
	private int code;
	private final String word;
	private String label;
	private String description;

	public Sensitivity(Double score, String word) {
		this.score = score;
		this.word = word;
		updateScore();
	}
	
	public void setWord(String word) {
//		this.word = word;
	}
	
	public String getWord() {
		return word;
	}

	public Double getScore() {
		return score;
	}

	public String getLabel() {
		return label;
	}

	public String getDescription() {
		return description;
	}

	public Sensitivity getOpposite(String prev) {
		if (score == null)
			return new Sensitivity(null, prev + word);
		return new Sensitivity(-score, prev + word);
	}

	private void updateScore() {
		if (score == null) {
			updateLabelAndDescription(NOT_DETERMINED);
			return;
		}
		if (score >= 0.75) {
			updateLabelAndDescription(STRONG_POSITIVE);
		} else if (score > 0.25 && score <= 0.5) {
			updateLabelAndDescription(POSITIVE);
		} else if (score > 0 && score <= 0.25) {
			updateLabelAndDescription(WEAK_POSITIVE);
		} else if (score < 0 && score >= -0.25) {
			updateLabelAndDescription(WEAK_NEGATIVE);
		} else if (score < -0.25 && score >= -0.5) {
			updateLabelAndDescription(NEGATIVE);
		} else if (score <= -0.75) {
			updateLabelAndDescription(STRONG_NEGATIVE);
		} else {
			updateLabelAndDescription(NORMAL);
		}
	}

	private void updateLabelAndDescription(Object[] s) {
		code = (int) s[0];
		label = (String) s[1];
		description = (String) s[2];
	}
	
	public boolean isNotDetermined() {
		return score == null;
	}

	@Override
	public String toString() {
		return description;
	}

	@Override
	public int compareTo(Sensitivity o) {
		return code - o.code;
	}
	
	@Override
	public int hashCode() {
		return code;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || getClass() != obj.getClass()) {
			return false;
		}
		final Sensitivity other = (Sensitivity) obj;
		return this.code == other.code;
	}
}
